package com.elbis.email.generator;

import java.util.Random;

public class TokenGenerator {

	private static final int tokenLength = 30;

	private TokenGenerator() {
	}

	public static String generateToken() {
		String token = null;
		Long now = System.currentTimeMillis();
		Random randomGenerator = new Random(now);
		Long random = randomGenerator.nextLong();
		token = String.valueOf(random);
		while (token.length() < tokenLength) {
			String scrambled = scramble(randomGenerator, token);
			token += scrambled;
		}
		token = token.substring(0, tokenLength);
		return token;
	}

	private static String scramble(Random random, String inputString) {
		char a[] = inputString.toCharArray();
		for (int i = 0; i < a.length - 1; i++) {
			int j = random.nextInt(a.length - 1);
			char temp = a[i];
			a[i] = a[j];
			a[j] = temp;
		}
		return new String(a);
	}

}
